<?php 
require('../../../wp-config.php');
global $wpdb;
$plugin_url = trailingslashit( WP_PLUGIN_URL.'/'. dirname( plugin_basename(__FILE__)));
$pageNum = 1;
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
$rowsPerPage = 5;
$offset = ($pageNum - 1) * $rowsPerPage;
$maxPage = ceil($wpdb->get_var("SELECT COUNT(*) FROM wp_house")/$rowsPerPage);?>
<div id="loading" align="center" style="display:none;"><img src="<?php echo $plugin_url;?>images/loading.gif" /><br />Loading...</div>
<a class="button add-new-h2" href="javascript:void(0);" onclick="add_house();">Add New</a>
<br />
<table class="wp-list-table widefat fixed posts" cellspacing="0" cellpadding="0" style="margin-top:10px;">
	<thead>
	<tr>
                <th scope='col' id='title' class='manage-column column-title'  style="width:6%;"><span>Image</span></th>
                <th scope='col' id='author' class='manage-column column-author'  style="width:4%"><span>Code</span></th>
                <th scope='col' id='categories' class='manage-column column-categories'  style="">Name</th>
                <th scope='col' id='categories' class='manage-column column-categories'  style="">Price</th>
                <th scope='col' id='date' class='manage-column column-date'  style=""><span>Date</span></th>
        </tr>
        </thead>

	<tfoot>
	<tr>
                <th scope='col' id='title' class='manage-column column-title'  style="width:6%;"><span>Image</span></th>
                <th scope='col' id='author' class='manage-column column-author'  style="width:4%"><span>Code</span></th>
                <th scope='col' id='categories' class='manage-column column-categories'  style="">Name</th>
                <th scope='col' id='categories' class='manage-column column-categories'  style="">Price</th>
                <th scope='col' id='date' class='manage-column column-date'  style=""><span>Date</span></th>
        </tr>
        </tfoot>

	<tbody id="the-list">
            <?php foreach($wpdb->get_results("SELECT * FROM wp_house LIMIT $offset, $rowsPerPage") as $row):?>
		<tr>

						<td class="post-title page-title column-title"><img src="<?php echo $wpdb->get_var("SELECT link FROM wp_image WHERE id_house= ".$row->id." AND main=1");?>"  width="100"/>
<div class="row-actions"><span class='edit'><a href="javascript:void" title="Edit this house" onclick="edit_house(<?php echo $row->id;?>);">Edit</a> | </span><span class='trash'><a class='submitdelete' title='Move this house to the Trash' href='javascript:void(0);' onclick="delete_house(<?php echo $row->id;?>,'<?php echo $row->name;?>')">Trash</a></div>

</td>			<td class="author column-author"><?php echo $row->code;?></td>
						<td class="categories column-categories"><?php echo $row->name;?></td>
                                                <td class="categories column-categories"><?php echo $row->price;?></td>
						

			<td class="date column-date"><?php echo $row->date;?></td>
                </tr>
                <?php endforeach;?>

		</tbody>
</table>
<center>
    <?php for($i=1;$i<=$maxPage;$i++){
     if($i != $pageNum){
         echo "<a href='javascript:load_page($i);'>".$i."</a>";
     }
     else
     {
         echo $i;
     }
     echo '&nbsp;';
    }?>
</center>


	